﻿using Cysharp.Threading.Tasks;
using Framework.Manager;
using Framework.Task;
using Game.Logic.Lobby;
using Logic.UI.Loading;
using Shared.UI;

namespace Logic.Helper
{
    public static class SwitchSceneHelper
    {
        public static async UniTask Login2Lobby()
        {
            await UniTask.CompletedTask;
            
            TaskManager.Instance.Reset();
            TaskManager.Instance.Add(new Task_LoadUI<Loading>(1, UIId.Loading, null, null));
            TaskManager.Instance.Add(new Task_Exec(1, async () =>
            {
                UIManager.Instance.AddLock(UIId.Loading);
                
                await UniTask.CompletedTask;
            }));
            TaskManager.Instance.Add(new Task_UnloadResources(1));
            TaskManager.Instance.Add(new Task_LoadScene(1, "Assets/Scenes/Lobby.unity", true));
            TaskManager.Instance.Add(new Task_LoadUI<Lobby>(1, UIId.Lobby, null, null));
            TaskManager.Instance.Add(new Task_ActiveScene(1));
            TaskManager.Instance.Add(new Task_Exec(1, async () =>
            {
                UIManager.Instance.RemoveLock(UIId.Loading);
                await UniTask.CompletedTask;
            }));
            await TaskManager.Instance.Start();
        }
    }
}